package com.cx.mall.search.service.impl;

import com.alibaba.fastjson.JSON;
import com.cx.mall.api.goods.SkuInfoFeign;
import com.cx.mall.common.entity.search.SkuEs;
import com.cx.mall.common.util.ResponseVo;
import com.cx.mall.search.mapper.SkuEsMapper;
import com.cx.mall.search.service.ISkuEsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SkuEsServiceImpl implements ISkuEsService {
    @Autowired
    private SkuEsMapper skuEsMapper;
     @Autowired
     private SkuInfoFeign skuInfoFeign;
    @Override
    public void saveAll() {
        ResponseVo responseVO = skuInfoFeign.listAll();
        if(responseVO.getCode() != 2000){
            throw  new RuntimeException(responseVO.getMsg());
        }
        List<SkuEs> skuEs = JSON.parseArray(JSON.toJSONString(responseVO.getData()), SkuEs.class);
        skuEsMapper.saveAll( skuEs);
    }
}